package com.mohe.shanpao.controller.user;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mohe.shanpao.controller.BaseController;
import com.mohe.shanpao.service.user.SysRoleService;
import com.mohe.shanpao.utils.Constants;

/**
 * 
 * 角色Controller
 * <功能详细描述>
 * 
 * @author  lizhi
 * @version  [版本号, 2016年6月28日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController
{
	private final static Logger logger = LoggerFactory.getLogger(RoleController.class);
	
    @Autowired
    private SysRoleService sysRoleService;
    
    /**
     * 
     * 获取角色list
     * <功能详细描述>
     * @param sysRole
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping("/query")
    @ResponseBody
    public Object query(HttpServletRequest request)
    {
    	String url = request.getRequestURI();
    	
    	if(SecurityUtils.getSubject().isPermitted(Constants.PERMS_MAP.get(url)))
    	{
    		logger.debug(url + " is permit success ");
    		
    		return sysRoleService.selectAll();
    	}
    	else
    	{
    		logger.error(url + " is permit fail ");
    		
    		return null;
    	}
        
    }
    
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(HttpServletRequest request)
    {
    	String url = request.getRequestURI();
    	
    	if(SecurityUtils.getSubject().isPermitted(Constants.PERMS_MAP.get(url)))
    	{
    		logger.debug(url + " is permit success ");
    		
    		return sysRoleService.selectById(2L);
    	}
    	else
    	{
    		logger.error(url + " is permit fail ");
    		
    		return null;
    	}
        
    }
    
}
